<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui"
      xmlns:f="http://java.sun.com/jsf/core">

    <ui:composition template="layout.xhtml">
        <ui:define name="body">

            <br/>
            <h3 class="title">Pesquisar DNE</h3>
            <h:form id="dneForm" enctype="multipart/form-data">
                <p:panel id="personPanel" style="background: none; border: none;" 
                         styleClass="container_24 clearfix both ">
                    <h4 class="title">Filtros</h4>

                    <p:outputLabel value="CEP:" styleClass="grid_3" for="cepMask" />
                    <p:inputMask id="cepMask" value="#{managerDne.dne.cep}" mask="99.999-999"
                                 styleClass="grid_5"/>
                    <div class="clear-both" />

                    <p:outputLabel for="patioInput" value="Logradouro" styleClass="grid_3"/>
                    <p:inputText id="patioInput" value="#{managerDne.dne.patio}"
                                 styleClass="grid_20" /> 
                    <div class="clear-both" />

                    <!--                    <p:outputLabel value="Nome:" styleClass="grid_3" for="nomeclogInputText" />
                                        <p:inputText id="nomeclogInputText" styleClass="grid_20" value="#{managerDne.dne.nomeclog}" />-->

                    <p:outputLabel value="Cidade:" styleClass="grid_3" for="cidadeInputText" />
                    <p:autoComplete id="cidadeInputText" value="#{managerDne.city}" var="item"
                                    forceSelection="true" dropdown="true" styleClass="grid_21"
                                    itemValue="#{item}" itemLabel="#{item.name}" panelStyle="height:200px;"
                                    completeMethod="#{managerDne.autocompleteCity}" 
                                    converter="cityconverter" />

                    <div class="clear-both" />
                    <p:outputLabel value="Bairro" styleClass="grid_3" for="bairroInputText" />
                    <p:autoComplete id="bairroInputText" value="#{managerDne.bairro}" var="itemdne"
                                    forceSelection="true" dropdown="true" styleClass="grid_21"
                                    panelStyle="height:200px;"
                                    itemValue="#{itemdne}" itemLabel="#{itemdne.nome}"
                                    converter="bairroconverter"
                                    completeMethod="#{managerDne.autocompleteBairro}" />

                    <div class="clear"/> 
                </p:panel>

                <br/>
                <div class="buttonAction">
                    <p:commandButton value="Pesquisar" icon="ui-icon-search"
                                     update="resultPanel" id="bt_add"
                                     actionListener="#{managerDne.search()}"
                                     styleClass="ui-priority-primary" />

                    <p:commandButton id="bt_clear" value="Limpar" icon="ui-icon-close"
                                     actionListener="#{managerDne.clear()}"
                                     update="@form" />
                </div >

                <p:blockUI id="BLOCK" block="resultPanel" trigger="bt_add" > 
                    <p:graphicImage value="media/images/ajax-loader.gif"/>
                </p:blockUI> 
                <p:blockUI id="BLOCK_CLEAR" block="resultPanel" trigger="bt_clear" > 
                    <p:graphicImage value="media/images/ajax-loader.gif"/>
                </p:blockUI>

                <h4 class="title">Resultado</h4>
                <p:panel id="resultPanel" styleClass="container_24 clearfix both" style="border: none" >
                    <p:dataTable id="resultDataTable" var="item" value="#{managerDne.dneResult}"
                                 styleClass="grid_24" rowIndexVar="rowid" 
                                 rowKey="#{item.id}" rows="5" paginator="true"  
                                 paginatorPosition="bottom" emptyMessage="Nenhum registro"> 
                        <f:facet name="header">
                            <p:outputLabel value="DNE #{managerDne.dneResult eq null ? '' : '('.concat(managerDne.dneResult.size()).concat(')')}" />
                        </f:facet>
                        <p:column headerText="Ação" width="20" style="text-align: center">
                            <p:button  style="width: 20px; height: 20px;" 
                                       title="Editar"
                                       href="editardne.xhtml?vDne=#{item.id}"
                                       icon="ui-icon-pencil"/>
                            <p:button  style="width: 20px; height: 20px;" 
                                       title="Visualizar"
                                       href="visualizardne.xhtml?vDne=#{item.id}"
                                       icon="ui-icon-zoomin"/>
                            <p:commandButton  style="width: 20px; height: 20px;" 
                                              update="@form" title="Excluir"
                                              oncomplete="dlg.show()"
                                              icon="ui-icon-trash">
                                <f:setPropertyActionListener target="#{managerDne.deleteDne}" value="#{item}" />
                            </p:commandButton>
                        </p:column>
                        <p:column headerText="CEP" style="text-align: center">
                            <h:outputText value="#{item.cep}" />
                        </p:column>
                        <p:column headerText="Logradouro" style="text-align: center">
                            <h:outputText value="#{item.nomeclog}" />
                        </p:column>
                        <p:column headerText="Cidade" style="text-align: center">
                            <h:outputText value="#{item.city.name}" />
                        </p:column>
                        <p:column headerText="Bairro" style="text-align: center">
                            <h:outputText value="#{item.bairro.nome}" />
                        </p:column>
                    </p:dataTable>
                </p:panel>

                <p:dialog id="modalDialog" header="Confirmação de remoção" widgetVar="dlg" modal="true" 
                          height="80" closable="false" resizable="false" >
                    <h:outputText value="Tem certeza que deseja remover este endereço da base DNE?" />
                    <div class="buttonAction">
                        <p:commandButton value="Sim"
                                         actionListener="#{managerDne.delete()}"
                                         update="@form"
                                         icon="ui-icon-check"/>
                        <p:commandButton value="Não" icon="ui-icon-close"
                                         oncomplete="dlg.hide()" />
                    </div>
                </p:dialog>
            </h:form>
        </ui:define>
    </ui:composition>

</html>
